import React from 'react'
import ReactDOM from 'react-dom'
import TestUtils from 'react-addons-test-utils'
import CheckboxWithLabel from '../CheckboxWithLabel'

jest.autoMockOff()

/*
对于`js`模块
export default CheckboxWithLabel
在这个例子下面
require('../CheckboxWithLabel') // 返回值是不同的
// require output -> { default: [Function: CheckboxWithLabel] }
import CheckboxWithLabel from '../CheckboxWithLabel' // 返回值是不同的
// import output -> [Function: CheckboxWithLabel]
 */

describe('CheckboxWithLabel', () => {
  const checkbox = TestUtils.renderIntoDocument(
    <CheckboxWithLabel
      labelOn="on"
      labelOff="off"
    />
  )

  const checkboxNode = ReactDOM.findDOMNode(checkbox)

  it('defaults to off label', () => {
    // Verify that it's Off by default
    expect(checkboxNode.textContent).toEqual('off')
  })

  it('default to unchecked', () => {
    const checkboxElm = TestUtils.findRenderedDOMComponentWithTag(checkbox, 'input')
    expect(checkboxElm.checked).toBe(false)
  })

  it('changes the label', () => {
    TestUtils.Simulate.change(
      TestUtils.findRenderedDOMComponentWithTag(checkbox, 'input')
    )
    expect(checkboxNode.textContent).toEqual('on')
  })

  it('test click input of checkbox', () => {
    TestUtils.Simulate.click(
      TestUtils.findRenderedDOMComponentWithTag(checkbox, 'input')
    )
    expect(checkboxNode.textContent).toBe('off')
  })
})